﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HalconDotNet;

namespace AssemblyCYG
{
    [Serializable]
    public class ProjectPara
    {
        #region 相机参数
        //对位下相机
        public int downCamIndex { get; set; }       //下相机索引
        public string downCamName { get; set; }     //名称
        public float downCamExposure { get; set; }   //曝光
        public float downCamGain { get; set; }       //增益
        public float downCamGamma { get; set; }      //伽马
        //对位上相机
        public int upCamIndex { get; set; }         //上相机索引
        public string upCamName { get; set; }      //名称  
        public float upCamExposure1 { get; set; }   //曝光
        public float upCamGain1 { get; set; }       //增益
        public float upCamGamma1 { get; set; }      //伽马

        public float upCamExposure2 { get; set; }   //曝光
        public float upCamGain2 { get; set; }       //增益
        public float upCamGamma2 { get; set; }      //伽马

        //自检相机
        public int reviewCamIndex { get; set; }         //自检相机索引
        public string reviewCamName { get; set; }      //名称  
        public float reviewCamExposure1 { get; set; }   //曝光
        public float reviewCamGain1 { get; set; }       //增益
        public float reviewCamExposure2 { get; set; }   //曝光
        public float reviewCamGain2 { get; set; }       //增益
        public float reviewCamExposure3 { get; set; }   //曝光
        public float reviewCamGain3 { get; set; }       //增益
        //胶形检测相机
        public int glueCamIndex { get; set; }         //胶形检测相机索引
        public string glueCamName { get; set; }      //名称  
        public float glueCamExposure { get; set; }   //曝光
        public float glueCamGain { get; set; }       //增益
        //引导相机
        public int guideCamIndex { get; set; }         //机械手引导检测相机索引
        public string guideCamName { get; set; }      //名称  
        public float guideCamExposure { get; set; }   //曝光
        public float guideCamGain { get; set; }       //增益
        //撕膜工位曝光参数（下相机）
        public float simoCamExposure { get; set; }   //曝光
        public float simoCamGamma { get; set; }      //伽马
        //扫码工位曝光参数（下相机）
        public float scanCodeCamExposure { get; set; }   //曝光
        public float scanCodeCamGamma { get; set; }      //伽马
        #endregion

        #region 引导定位参数
        public FitCirclePara guideFitCirclePara { get; set; }    //引导定位参数
        #endregion

        #region 上相机1定位参数
        public FitCirclePara upCamLocateFitCirclePara { get; set; }    //上相机定位参数
        public FitLinePara upCamLocateFitLine1Para { get; set; }       //上相机定位参数
        public FitLinePara upCamLocateFitLine2Para { get; set; }
        public double upCamLocateOutCircleRadius { get; set; }         //上相机定位外围圆半径
        public double upCamLocateSeekCornerStartPhi { get; set; }      //寻找交点的起始角度
        public double upCamLocateSeekCornerEndPhi { get; set; }        //寻找交点的终止角度
        public MatchPara upCamLocateMatchPara { get; set; }
        #endregion

        #region 上相机2定位参数
        public FitCirclePara upCamLocateFitCirclePara2 { get; set; }    //上相机定位参数
        public FitLinePara upCamLocateFitLine1Para2 { get; set; }       //上相机定位参数
        public FitLinePara upCamLocateFitLine2Para2 { get; set; }
        public double upCamLocateOutCircleRadius2 { get; set; }         //上相机定位外围圆半径
        public double upCamLocateSeekCornerStartPhi2 { get; set; }      //寻找交点的起始角度
        public double upCamLocateSeekCornerEndPhi2 { get; set; }        //寻找交点的终止角度
        public MatchPara upCamLocateMatchPara2 { get; set; }
        #endregion

        #region 下相机定位参数
        public FitCirclePara downCamLocateFitCirclePara { get; set; }    //下相机定位参数
        public FitLinePara downCamLocateFitLine1Para { get; set; }       //下相机定位参数
        public FitLinePara downCamLocateFitLine2Para { get; set; }
        public double downCamLocateOutCircleRadius { get; set; }         //下相机定位外围圆半径
        public double simoROI1R1 { get; set; }         //撕膜ROI1
        public double simoROI1C1 { get; set; }
        public double simoROI1R2 { get; set; }
        public double simoROI1C2 { get; set; }
        public double simoROI2R1 { get; set; }         //撕膜ROI2
        public double simoROI2C1 { get; set; }
        public double simoROI2R2 { get; set; }
        public double simoROI2C2 { get; set; } 
        
        public double downCamLocateSeekCornerStartPhi { get; set; }      //寻找交点的起始角度
        public double downCamLocateSeekCornerEndPhi { get; set; }        //寻找交点的终止角度
        public MatchPara downCamLocateMatchPara { get; set; }  

        #endregion

        #region 标定算法参数
        public FitCirclePara calibFitCirclePara { get; set; }    //下相机定位参数
        public FitLinePara calibFitLine1Para { get; set; }       //下相机定位参数
        public FitLinePara calibFitLine2Para { get; set; }
        public double calibOutCircleRadius { get; set; }         //下相机定位外围圆半径
        public double calibSeekCornerStartPhi { get; set; }      //寻找交点的起始角度
        public double calibSeekCornerEndPhi { get; set; }        //寻找交点的终止角度
        public MatchPara calibMatchPara { get; set; }

        public FitCirclePara calibUpFitCirclePara { get; set; }    //下相机定位参数
        public FitLinePara calibUpFitLine1Para { get; set; }       //下相机定位参数
        public FitLinePara calibUpFitLine2Para { get; set; }
        public double calibUpOutCircleRadius { get; set; }         //下相机定位外围圆半径
        public double calibUpSeekCornerStartPhi { get; set; }      //寻找交点的起始角度
        public double calibUpSeekCornerEndPhi { get; set; }        //寻找交点的终止角度
        public MatchPara calibUpMatchPara { get; set; }
        #endregion

        #region coil复检参数
        public FitCirclePara coilReviewFitCircle1 { get; set; }
        public FitCirclePara coilReviewFitCircle2 { get; set; }
        public FitLinePara coilReviewFitSRLine1 { get; set; }
        public FitLinePara coilReviewFitSRLine2 { get; set; }
        public FitLinePara coilReviewFitLine3 { get; set; }
        public FitLinePara coilReviewFitLine4 { get; set; }
        public double coilReviewLineCornerStartPhi { get; set; }
        public double coilReviewLineCornerEndPhi { get; set; }
        public double coilReviewOutCircleRadius { get; set; }
        public MatchPara coilReview1MatchPara { get; set; }
        public MatchPara coilReview2MatchPara { get; set; } 
        #endregion

        #region 复检相机检测参数
        public FitCirclePara reviewLowFitCirclePara { get; set; }    //
        public FitLinePara reviewLowSpringLine1Para { get; set; }       //
        public FitLinePara reviewLowSpringLine2Para { get; set; }
        public FitLinePara reviewLowPartLine1Para { get; set; }       //
        public FitLinePara reviewLowPartLine2Para { get; set; }
        public double reviewSpringOutCircleRadius { get; set; }         //
        public double reviewPartOutCircleRadius { get; set; }
        public double reviewSeekCornerStartPhi { get; set; }      //寻找交点的起始角度
        public double reviewSeekCornerEndPhi { get; set; }        //寻找交点的终止角度
        public MatchPara reviewLowMatchPara { get; set; }
        public FitCirclePara reviewHighFitCirclePara { get; set; }    //
        #endregion

        #region 胶形检测
        public BlobDetectPara glueDetectPara { get; set; }      //暂定胶形检测
        public FitCirclePara springGlueDetectPara { get; set; } //环形胶形检测
        #endregion

        #region 通讯参数
        public string tcpIpAddress { get; set; }   //通讯tcpIP地址
        public int tcpPort { get; set; }          //通讯ipprot
        public string scannerIpAddress{ get; set; }  //扫码枪ip地址
        #endregion

        #region 定位限制参数
        public double maxAngleOffset { get; set; }   //旋转角度最大限度
        public double maxXOffset { get; set; }       //x偏差量最大限度
        public double maxYOffset { get; set; }
        public double buChang_Angle1 { get; set; }    //角度硬补偿
        public double buChang_X1 { get; set; }        //x轴方向硬补偿
        public double buChang_Y1 { get; set; }        //y轴方向硬补偿

        //流道2补偿
        public double buChang_Angle2 { get; set; }    //角度硬补偿
        public double buChang_X2 { get; set; }        //x轴方向硬补偿
        public double buChang_Y2 { get; set; }        //y轴方向硬补偿
        public double oKRotateAngle { get; set; }     //调整完成允许的最大旋转角度
        #endregion

        #region 自检参数
        public double reviewMaxPosOffset { get; set; }      //自检位置最大偏差
        public double reviewMaxAngleOffset { get; set; }    //自检角度最大偏差
        #endregion

        #region 保存图像参数
        public int saveImageType { get; set; }         //保存图像类型，0为不保存，1为保存全部图像，2为只保存NG图像
        public int saveImageFormat { get; set; }       //保存图像格式
        public string saveImagePath { get; set; }      //保存图像的路径
        public int saveImageDays { get; set; }         //保存图像的存留期限
        public bool isSaveDetectImage { get; set; }    //是否保存检测效果图
        #endregion

        #region 报表参数
        public bool isSaveReport { get; set; }        //是否输出报表
        public string saveReportPath { get; set; }    //报表保存路径
        #endregion

        #region “Puck定位圆相关数据”
        public int innerRadius;
        public int outerRadius;
        #endregion
        public static ProjectPara GetDefaultDeviceParameter()
        {
            ProjectPara dp = new ProjectPara();
            dp.tcpIpAddress = "192.168.1.64";
            dp.tcpPort = 502;
            return dp;
        }
    }
    [Serializable]
    public class FitCirclePara  
    {
        //拟合圆参数
        public int minGray { get; set; }   //拟合圆最小灰度
        public int maxGray { get; set; }   //拟合圆最大灰度
        //public int fitType { get; set; }   //的拟合方式
        public HObject ho_ROI { get; set; }    //拟合圆检测区域
        public int contrast { get; set; }  //对比度
        public int fitNum { get; set; }    //圆拟合数量
        public int sigma { get; set; }     //平滑
        public int seekPointPath { get; set; }    //搜索方向
        public bool isInheritModel { get; set; }  //是否继承模板
        public double limitMinRingWidth { get; set; }    //限制圆环的最小宽度
        public double limitMaxRingWidth { get; set; }    //限制圆环的最大宽度 
    }
    [Serializable]
    public class FitLinePara
    {
        //拟合直线参数
        public int contrast { get; set; }    //最小边缘幅度，对比度
        public int sigma { get; set; }      //sigma
        public int grayTransition { get; set; }    //灰度变换
        public int pointPosition { get; set; }
        public int fitNum { get; set; }    //拟合点的数量
        public HObject ho_ROI { get; set; }        //线1检测区域
        public int LSJudge { get; set; }       //长短边判断，length1 > length2则为true,否则false
        public double LSAngle { get; set; }      //角度
        public bool isInheritModel { get; set; }  //是否继承模板
    }
    [Serializable]
    public class MatchPara
    {
        //匹配参数
        public double modelLocationRow { get; set; } //模板定位的行坐标，用于放射转换,
        public double modelLocationCol { get; set; } //模板定位的列坐标
        public HObject modelROI { get; set; }        //模板ROI
        //public HTuple hv_Model { get; set; }         //模板
        public int seekModelNum { get; set; }        //搜索模板的数量
        public int seekModelScore { get; set; }      //搜索模板的得分
        public int seekAngleStart { get; set; }      //搜寻模板的最小角度
        public int seekAngleRange { get; set; }      //搜寻模板的最大角度
        public int modelMatchType { get; set; }      //模板匹配的类型，基于形状or灰度
    }
    [Serializable]
    public class BlobDetectPara
    {
        public HObject detectROI { get; set; }   //检测ROI
        public int detectType { get; set; }     //检测方式，0为普通阈值，1为高级阈值
        public int minGray { get; set; }     //普通阈值，最小灰度
        public int maxGray { get; set; }     //普通阈值，最大灰度
        public int mask { get; set; }        //var掩码
        public double stdDevScale { get; set; }    //var偏差因子
        public int absThreshold { get; set; }    //var阈值
        public int lightDark { get; set; }      //var缺陷类型，0dark,1equal,2light,3not_equal
        public double meanRadius { get; set; }     //mean算子模糊因子
        public double closeRadius { get; set; }   //缺陷闭运算
        public double openRadius { get; set; }     //缺陷开运算
        public int areaFilter { get; set; }   //面积初次筛选过滤，单位像素
        public double minArea { get; set; }   //最小面积
        public double maxArea { get; set; }   //最大面积
        public int minMean { get; set; }   //最小亮度
        public int maxMean { get; set; }   //最大亮度
        public int minNum { get; set; }   //最小数量
        public int maxNum { get; set; }   //最大数量
        public bool addArea { get; set; }   //增加面积
        public bool addMean { get; set; }   //增加亮度
        public bool addNum { get; set; }   //增加数量
        public bool isInheritModel { get; set; }  //是否继承模板
    }
}
